import numpy as np
import pandas as pd
import requests
from lxml import etree
import datetime
import time
import lxml


d1 = datetime.datetime.now() 
d2 = d1 - datetime.timedelta(days=2)
s=d2.strftime("%Y-%m-%d")

def GetDayData(date):
    url = "http://kaijiang.aicai.com/open/kcResultByDate.do"
    args = {"gameIndex":"301","searchDate":date.strftime("%Y-%m-%d"),"gameFrom":""}
    s = requests.post(url, args).text;
    s = eval(s)["resultHtml"]
    page = etree.HTML(s.lower())
    openIssues = page.xpath(u"//tr//td")
    count = int(len(openIssues)/3)
    issue=[]
    no = []
    opentime = []
    for i in range(count):
        st = openIssues[i* 3].text
        st = st[:12]
        issue.append(st.replace("-",""))
        opentime.append(openIssues[i*3+1].text)
        no.append(openIssues[i*3+2].text)
    return issue,no,opentime   
def GetData(nCount):
    date1 = datetime.datetime.now()
    date2 = date1 - datetime.timedelta(days=nCount)
    issue = []
    no=[]
    opentime =[]
    for i in range(0,nCount):
        date3 = date2 + datetime.timedelta(days=i)
        issue1,no1,opentime1=GetDayData(date3)
        issue = issue1 + issue
        no = no1 + no
        opentime = opentime1 + opentime
    return issue,no,opentime
issue,no,opentime=GetData(10)
df = pd.DataFrame(index=issue,data=no)
print(df)
df['opentime']=opentime
df.to_csv("C:\\Users\\woddle\\Desktop\\1.csv")
